﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// Provides access to the elements of a collection through an index.
   /// </summary>
   /// <remarks>
   /// This interface should only be used if the data structure, itself, is indexed.
   /// </remarks>
   public class IndexAccess : ElementAccess, IIndexAccess
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public IndexAccess() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public IndexAccess(object comObject) :
         base(comObject)
      { }

      #endregion

      #region IIndexAccess

      /// <summary>
      /// Gets the number of elements in this container.
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public int Count 
      { 
         get
         {
            CheckDisposed();
            return (int)InvokeMethod("getCount");
         }
      }

      /// <summary>
      /// Gets the element at the specified index.
      /// </summary>
      /// <param name="index">Specifies the position in the array. The first index is 0.</param>
      /// <returns>Returns the element at the specified index.</returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public object GetByIndex(int index)
      {
         CheckDisposed();
         return InvokeMethod("getByIndex", index);
      }

      #endregion

      #region utility methods

      /// <summary>
      /// Gets the element by its index.
      /// </summary>
      /// <param name="index"></param>
      /// <returns></returns>
      public object this[int index]
      {
         get
         {
            return GetByIndex(index);
         }
      }

      #endregion
   }

   /// <summary>
   /// Provides access to the elements of a collection through an index.
   /// </summary>
   /// <remarks>
   /// This interface should only be used if the data structure, itself, is indexed.
   /// </remarks>
   public interface IIndexAccess
   {
      /// <summary>
      /// Gets the number of elements in this container.
      /// </summary>
      int Count { get; }

      /// <summary>
      /// Gets the element at the specified index.
      /// </summary>
      /// <param name="index">Specifies the position in the array. The first index is 0.</param>
      /// <returns>Returns the element at the specified index.</returns>
      object GetByIndex(int index);
   }
}
